﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using HappyFrogXna.DrawingSystem;
using HappyFrogXna.ScreenSystem;
using Microsoft.Xna.Framework.Graphics;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Factories;
using HappyFrogXna.Level;
using HappyFrogXna.Miscellaneous;
using System.Diagnostics;

namespace HappyFrogXna.Scene
{
    class BasicScene : IScene
    {
        Vector2 _slingshotCenterPos = new Vector2(16.1f, 19);
        public Vector2 SlingshotCenterPos { get { return _slingshotCenterPos; } }

        Vector2 _slingshotLeftPos = new Vector2(15.1f, 19.4f);
        public Vector2 SlingshotLeftPos { get { return _slingshotLeftPos; } }

        Vector2 _slingshotRightPos = new Vector2(16.2f, 19.3f);
        public Vector2 SlingshotRightPos { get { return _slingshotRightPos; } }

        public float GroundHorizontalLineY { get { return 24.8f; } }

        // screen background
        Sprite _groundSpriteLeft;
        Sprite _groundSpriteRight;

        float _scaleRatio;

        Color _bgColor;
        public Color BackgroundColor { get { return _bgColor; } }

        float _groundWidth;
        public float GroundWidthInDisplay { get { return _groundWidth * _scaleRatio; } }

        Body _ground;
        public Body Ground { get { return _ground; } }

        public BasicScene(World world)
        {
            _groundSpriteLeft = new Sprite(GolbalXnaGadgetProvider.Instance.Content.Load<Texture2D>(@"Images\basic_scene_left"));
            _groundSpriteRight = new Sprite(GolbalXnaGadgetProvider.Instance.Content.Load<Texture2D>(@"Images\basic_scene_right"));
            _scaleRatio = ScreenInfo.ScreenSize.Height / _groundSpriteLeft.Height;
            _groundWidth = _groundSpriteLeft.Width + _groundSpriteRight.Width;

            _ground = BodyFactory.CreateEdge(world, new Vector2(0, GroundHorizontalLineY),
                new Vector2(ConvertUnits.ToSimUnits(_groundWidth), GroundHorizontalLineY));
            _ground.IsStatic = true;
            _ground.Friction = 0.6f;

            _bgColor = new Color(183, 231, 251);
        }

        public void Draw()
        {
            GolbalXnaGadgetProvider.Instance.SpriteBatch.Draw(_groundSpriteLeft.Texture, new Vector2(0, 0), null, Color.White, 0.0f, new Vector2(0, 0), _scaleRatio, SpriteEffects.None, 1.0f);
            GolbalXnaGadgetProvider.Instance.SpriteBatch.Draw(_groundSpriteRight.Texture, new Vector2(_groundSpriteLeft.Width * _scaleRatio, 0), null, Color.White, 0.0f, new Vector2(0, 0), _scaleRatio, SpriteEffects.None, 1.0f);
        }
    }
}
